package question6;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class Main {

    public static int compare(String s, String t) {
        Map<Character, Character> map = new HashMap<>();
        char[] originChar = s.toCharArray();
        char[] destChar = t.toCharArray();
        if (originChar.length != destChar.length) {
            return 0;
        }
        Set<Character> destValue = new HashSet<>();
        for (int i = 0; i < originChar.length; i++) {
            if (map.containsKey(originChar[i])) {
                Character character = map.get(originChar[i]);
                if (destChar[i] != character) {
                    return 0;
                }
            }  else {
                if (!map.containsKey(originChar[i]) && destValue.contains(destChar[i])) {
                    return 0;
                }
                map.put(originChar[i], destChar[i]);
                destValue.add(destChar[i]);
            }
        }
        return 1;
    }

    public static void main(String[] args) {
        int compare = compare("foo", "bar");
        System.out.println(compare);
    }
}
